package com.g4.shoppingsingle.controller;


import com.g4.shoppingsingle.common.Result;
import com.g4.shoppingsingle.pojo.DdUsersInfo;
import com.g4.shoppingsingle.service.IDdUsersInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author admin
 * @since 2021-10-27
 */
@Slf4j  //日志打印
@RestController
@RequestMapping("/shoppingsingle/ddUsersInfo")
public class DdUsersInfoController {

    /**
     *依赖业务逻辑层
     */
    @Autowired(required = false)
    private IDdUsersInfoService iDdUsersInfoService;
    /**
     * 获取用户个人信息接口
     * @param userId
     * @return
     */
    @GetMapping("/userinfo/{userId}")
    public Result getMyInfo(@PathVariable Integer userId){

        log.info("接受到页面的请求,请求参数是--: " + userId);

        //调用业务逻辑层,获取个人信息
        DdUsersInfo ddUsersInfo = iDdUsersInfoService.getMyInfo(userId);

        log.info("从数据库中查询出来的数据是--: "+ ddUsersInfo.toString());
        return Result.ok(ddUsersInfo);
    }

    /**
     * 获取当前登录用户的信息
     * @return
     */
    @GetMapping("/me")
    public Result getMe() {
        try {
            DdUsersInfo ddUsersInfo = iDdUsersInfoService.getMe();
            return Result.ok("操作成功", ddUsersInfo);
        }catch (Exception e){
            return Result.error("操作失败",null);
        }
    }
}
